package com.wz.project.sap.DN_POST_DN.controller;

import java.util.List;

import com.wz.project.util.StringUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.sap.DN_POST_DN.domain.ZflWmsDnPostDn;
import com.wz.project.sap.DN_POST_DN.service.IZflWmsDnPostDnService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 内外向交货单过账Controller
 *
 * @author wz
 * @date 2022-09-19
 */
@Controller
@RequestMapping("/DN_POST_DN/DN_POST_DN")
public class ZflWmsDnPostDnController extends BaseController {
    private String prefix = "sap/ZflWmsDnPostDn";

    @Autowired
    private IZflWmsDnPostDnService zflWmsDnPostDnService;

//    @RequiresPermissions("DN_POST_DN:DN_POST_DN:view")
    @GetMapping()
    public String DN_POST_DN() {
        return prefix + "/ZflWmsDnPostDn";
    }

    /**
     * 查询内外向交货单过账列表
     */
//    @RequiresPermissions("DN_POST_DN:DN_POST_DN:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZflWmsDnPostDn zflWmsDnPostDn) {
        startPage();
        List<ZflWmsDnPostDn> list = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn);
        return getDataTable(list);
    }

    @PostMapping("/list1")
    @ResponseBody
    public TableDataInfo list1(ZflWmsDnPostDn zflWmsDnPostDn) {

        if (zflWmsDnPostDn.getVBELN() != null && !"".equals(zflWmsDnPostDn.getVBELN())) {
            zflWmsDnPostDn.setVBELN(String.format("%010d", Long.parseLong(zflWmsDnPostDn.getVBELN())));
        } else {
            zflWmsDnPostDn.setVBELN(String.format("%010d", 0));
        }

        startPage();
        List<ZflWmsDnPostDn> list = zflWmsDnPostDnService.selectZflWmsDnPostDnList1(zflWmsDnPostDn);
        return getDataTable(list);
    }

    /**
     * 导出内外向交货单过账列表
     */
//    @RequiresPermissions("DN_POST_DN:DN_POST_DN:export")
    @Log(title = "内外向交货单过账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZflWmsDnPostDn zflWmsDnPostDn) {
        List<ZflWmsDnPostDn> list = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn);
        ExcelUtil<ZflWmsDnPostDn> util = new ExcelUtil<ZflWmsDnPostDn>(ZflWmsDnPostDn.class);
        return util.exportExcel(list, "DN_POST_DN");
    }

    /**
     * 新增内外向交货单过账
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存内外向交货单过账
     */
    @RequiresPermissions("DN_POST_DN:DN_POST_DN:add")
    @Log(title = "内外向交货单过账", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZflWmsDnPostDn zflWmsDnPostDn) {
        zflWmsDnPostDn.setStatus("0");
        zflWmsDnPostDn.setMATNR(StringUtil.Stringadd(zflWmsDnPostDn.getMATNR()));
        return toAjax(zflWmsDnPostDnService.insertZflWmsDnPostDn(zflWmsDnPostDn));
    }

    /**
     * 修改内外向交货单过账
     */
    @GetMapping("/edit")
    public String edit(String zeile, String vbeln, ModelMap mmap) {
        ZflWmsDnPostDn zflWmsDnPostDn1 = new ZflWmsDnPostDn();
        zflWmsDnPostDn1.setZEILE(zeile);
        zflWmsDnPostDn1.setVBELN(vbeln);
        List<ZflWmsDnPostDn> zflWmsDnPostDns = zflWmsDnPostDnService.selectZflWmsDnPostDnList(zflWmsDnPostDn1);
        mmap.put("zflWmsDnPostDn", zflWmsDnPostDns.get(0));
        return prefix + "/edit";
    }

    /**
     * 修改保存内外向交货单过账
     */
    @RequiresPermissions("DN_POST_DN:DN_POST_DN:edit")
    @Log(title = "内外向交货单过账", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZflWmsDnPostDn zflWmsDnPostDn) {
        return toAjax(zflWmsDnPostDnService.updateZflWmsDnPostDn(zflWmsDnPostDn));
    }

    /**
     * 修改内外向交货单过账、质检状态
     */
    @RequiresPermissions("DN_POST_DN:DN_POST_DN:edit")
    @Log(title = "内外向交货单过账", businessType = BusinessType.UPDATE)
    @PostMapping("/editStatus")
    @ResponseBody
    public AjaxResult editStatus(ZflWmsDnPostDn zflWmsDnPostDn) {
        return toAjax(zflWmsDnPostDnService.editStatus(zflWmsDnPostDn));
    }

    /**
     * 删除内外向交货单过账
     */
    @RequiresPermissions("DN_POST_DN:DN_POST_DN:remove")
    @Log(title = "内外向交货单过账", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(zflWmsDnPostDnService.deleteZflWmsDnPostDnByIds(ids));
    }
}
